package com.zd.util;


import com.zd.entity.News;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

//封装每页的数据
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageUtil {
    private Integer pageNo;//当前页号
    private Integer pageSize = Constant.PAGESIZE;//页面大小
    private Integer totalCount;//总记录数
    private Integer totalPageCount;//总页数

    private List<News> newsList;//每页的数据

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        //计算总页数
        this.totalPageCount = (totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1);
    }

    public void setPageNo(Integer pageNo) {
        if(pageNo>totalPageCount)
            pageNo=totalPageCount;
        this.pageNo = pageNo;
    }
}
